package com.nine.spi;

import com.nine.spi.inter.Car;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.ServiceLoader;

@SpringBootApplication
public class SpiApplication implements CommandLineRunner {



    public static void main(String[] args) {
        SpringApplication.run(SpiApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        String carName = "aodi";
        // String carName = "bmw";
        ServiceLoader<Car> serviceLoader = ServiceLoader.load(Car.class);
        for (Car car : serviceLoader) {
            // 判断是否支持当前车型
            if (car.isSupport(carName)) {
                car.start();
                car.run();
                car.stop();
            }
        }
        System.out.println("SPI 加载完成");
    }
}
